package na.learn.java.jmx.sampleprogs.stdmbean;

import javax.management.AttributeChangeNotification;
import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;

public class SimpleCache extends NotificationBroadcasterSupport implements
		SimpleCacheMBean {

	public int getSize() {

		return Size;
	}

	public void setSize(int size) {
		AttributeChangeNotification notification = new AttributeChangeNotification(
				 this, -1, System.currentTimeMillis(), "Setting size to " + size , "size", "String", this.Size, size);
		sendNotification(notification);
		this.Size = size;

	}

	public void clear() {
		Notification notification = new Notification(
				"na.learn.java.jmx.sampleprogs.stdmbean.SimpleCache", this, 0,
				System.currentTimeMillis(), "SimpleCache " + this.CacheName
						+ " cleared.");
		sendNotification(notification);

		cachedObjects = null;

	}

	public String getCachedObjects() {
		return cachedObjects;
	}

	public void setCachedObjects(String cachedObjects) {
		AttributeChangeNotification notification = new AttributeChangeNotification(
				this, 1, System.currentTimeMillis(), "Setting cahced objects. ", "cachedObjects", "String", this.cachedObjects, cachedObjects);
		sendNotification(notification);
		this.cachedObjects = cachedObjects;
	}

	public String getCacheName() {
		return CacheName;
	}

	public void setCacheName(String cacheName) {
		AttributeChangeNotification notification = new AttributeChangeNotification(
				this, 2, System.currentTimeMillis(), "Set name of Cache to " + cacheName, " cacheName", "String", this.CacheName, cacheName );
		sendNotification(notification);
		this.CacheName = cacheName;
	}

	private String CacheName;

	private int Size;

	private String cachedObjects;

	public SimpleCache() {
		this("" + System.currentTimeMillis());
	}

	public SimpleCache(String name) {
		this.CacheName = name;

	}

}
